from rest_framework import serializers
from rest_framework.relations import PrimaryKeyRelatedField

from recruits.models import City, Recruit, Enterprise


class CityHotlistSerializers(serializers.ModelSerializer):


    class Meta:

        model = City

        fields = ('id','name','ishot')


class EnterpriseRecommandSerializers(serializers.ModelSerializer):

    recruits = PrimaryKeyRelatedField(label='职业',read_only=True,many=True)
    # recruits = serializers.PrimaryKeyRelatedField()

    class Meta:

        model = Enterprise

        fields = ('id','name','labels','logo','recruits','summary')


class SearchRecommandSerializers(serializers.ModelSerializer):

    enterprise = EnterpriseRecommandSerializers(label='企业',read_only=True)

    class Meta:

        model = Recruit

        exclude = ('address','state','detailcontent','detailrequire','visits','users')


class SearchHotlistEnterpriseSerializers(serializers.ModelSerializer):

    recruits = PrimaryKeyRelatedField(label='职业',read_only=True,many=True)

    class Meta:

        model = Enterprise
        fields = ('id','name','labels','logo','recruits','summary')


class EnterpriseCollectSerializers(serializers.ModelSerializer):

    success = serializers.BooleanField(label='收藏状态',default=True,read_only=True)

    message = serializers.CharField(label='状态信息',default='ok',read_only=True)

    id = serializers.CharField(label='id')

    users = serializers.CharField(label='用户',write_only=True)

    class Meta:

        model = Enterprise

        fields = ('id','success','message','users')

        extra_kwargs = {

            'users':{'required':False},
        }
